﻿using AutoMapper;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;


namespace U.Enterprise.Api.Applications.Client
{
    public class ClientSearchHandler : IRequestHandler<ClientSearchCommand, Resqults>
    {
        private readonly IBateRepository<Clients> clientBate;
        private readonly IMapper mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="clientBate"></param>
        /// <param name="mapper"></param>
        public ClientSearchHandler(IBateRepository<Clients> clientBate, IMapper mapper)
        {
            this.clientBate = clientBate;
            this.mapper = mapper;
        }
        /// <summary>
        /// 客户显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Resqults> Handle(ClientSearchCommand request, CancellationToken cancellationToken)
        {
            var resqults = new Resqults() { Code = 0 };
            try
            {
                var list = await clientBate.GetAll().Where(p=>p.DelStart == false).ToListAsync();
                if(list != null)
                {
                    resqults.Code = 1;
                    resqults.Date = list;
                    resqults.Messges = "客户显示成功";
                }
            }
            catch (Exception)
            {

                resqults.Messges = "客户显示失败";
            }
            return resqults;
        }
    }
}
